﻿using System;
using System.Collections;
using System.Xml;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;

namespace InfoJetSoft.Service.Worker
{
	
	class FormBuildComponentIdListWorker
	{
		
		public static void buildComponentIdList(Form form)
		{
			XmlElement root = form.XmlDoc.DocumentElement;
			ArrayList xmlToEditList = form.Manifest.XmlToEditList;
			ArrayList noBreakIdList = new ArrayList();
			ArrayList listIdList = new ArrayList();
			
			foreach (XmlToEdit xmlToEdit in xmlToEditList)
			{
				//CID 0543 //2010.04.30 //if
				if( xmlToEdit.ViewName.Equals( form.View.Name ) )
				{
					string component = xmlToEdit.Component;
					string type = xmlToEdit.Type;
					if (component != null && type != null)
					{
						if (component.Equals(JetConstant.CMP_xField))
						{
							if ((type.Equals(JetConstant.xField_Plain)) || (type.Equals(JetConstant.xField_Formatted)))
							{
								string item = xmlToEdit.Item;
								XmlNodeList itemXmlNodeList = DOMUtil.selectNodes(root, item, 0, form.XmlNsResolver);
								foreach (XmlNode itemNode in itemXmlNodeList)
								{
									//只有至少是Element元素才能是Rich.
									if (itemNode is XmlElement)
									{
										string nodeId = DOMUtil.getNodeJetId(itemNode);
										noBreakIdList.Add(nodeId);
									}
								}
							}
						}
							//CID 0236 //2009.03.03 //xmlToEdit.MultiSelectListBoxRef == null
						else if (component.Equals(JetConstant.CMP_xTextList ) && xmlToEdit.MultiSelectListBoxRef == null)
						{
							string item = xmlToEdit.Item;
							XmlNodeList itemXmlNodeList = DOMUtil.selectNodes(root, item, 0, form.XmlNsResolver);
							foreach (XmlNode itemNode in itemXmlNodeList)
							{
								string nodeId = DOMUtil.getNodeJetId(itemNode);
								nodeId += (JetConstant.INNER_SEPARATOR + xmlToEdit.Name);
								listIdList.Add(nodeId);
							}
						}
					}
				}
			}
			form.NoBreakIdList = noBreakIdList;
			form.ListIdList = listIdList;
		}
	}
}